package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntHospitalProject;
import com.nt.oam.service.IAntHospitalProjectService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 项目信息Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/project")
public class AntHospitalProjectController extends BaseController {
    @Autowired
    private IAntHospitalProjectService antHospitalProjectService;

    /**
     * 查询项目信息列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(AntHospitalProject antHospitalProject) {
        startPage();
        List<AntHospitalProject> list = antHospitalProjectService.selectAntHospitalProjectList(antHospitalProject);
        return getDataTable(list);
    }

    /**
     * 导出项目信息列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:export')")
    @Log(title = "项目信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AntHospitalProject antHospitalProject) {
        List<AntHospitalProject> list = antHospitalProjectService.selectAntHospitalProjectList(antHospitalProject);
        ExcelUtil<AntHospitalProject> util = new ExcelUtil<AntHospitalProject>(AntHospitalProject.class);
        util.exportExcel(response, list, "项目信息数据");
    }

    /**
     * 获取项目信息详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId) {
        return success(antHospitalProjectService.selectAntHospitalProjectByProjectId(projectId));
    }

    /**
     * 新增项目信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:add')")
    @Log(title = "项目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntHospitalProject antHospitalProject) {
        return toAjax(antHospitalProjectService.insertAntHospitalProject(antHospitalProject));
    }

    /**
     * 修改项目信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:edit')")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntHospitalProject antHospitalProject) {
        return toAjax(antHospitalProjectService.updateAntHospitalProject(antHospitalProject));
    }

    /**
     * 删除项目信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:remove')")
    @Log(title = "项目信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds) {
        return toAjax(antHospitalProjectService.deleteAntHospitalProjectByProjectIds(projectIds));
    }

    /**
     * 医院名称列表
     */
    @Anonymous
    @Log(title = "医院名称查询", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('oam:project:query')")
    @GetMapping("/hospital/name")
    public AjaxResult hospitalNameList(@RequestParam(required = false) String hospitalName) {
        return success(antHospitalProjectService.getHospitalNameList(hospitalName));
    }

    /**
     * 销售/交付人名称列表
     */
    @Anonymous
    @Log(title = "销售/交付人名称列表", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('oam:project:query')")
    @GetMapping("/person/name")
    public AjaxResult sellNameList(@RequestParam(required = false) String personName) {
        return success(antHospitalProjectService.getPersonNameList(personName));
    }

    /**
     * 医院负责人姓名列表
     */
    @Anonymous
    @Log(title = "医院负责人姓名列表", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('oam:project:query')")
    @GetMapping("/charge/name")
    public AjaxResult chargeNameList(@RequestParam(required = false) String chargeName) {
        return success(antHospitalProjectService.getChargeNameList(chargeName));
    }

    /**
     * 内部人员姓名列表
     */
    @Anonymous
    @Log(title = "医院负责人姓名列表", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('oam:project:query')")
    @GetMapping("/inner/name")
    public AjaxResult innerNameList(@RequestParam(required = false) String innerName) {
        return success(antHospitalProjectService.getInnerNameList(innerName));
    }

    /**
     * 项目名称列表
     */
    @Anonymous
    @Log(title = "项目名称列表", businessType = BusinessType.OTHER)
    @PreAuthorize("@ss.hasPermi('oam:project:query')")
    @GetMapping("/item/name")
    public AjaxResult itemNameList(@RequestParam(required = false) String itemName) {
        return success(antHospitalProjectService.getProjectNameList(itemName));
    }


    /**
     * 获取项目信息详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:query')")
    @GetMapping(value = "/details/{projectId}")
    public AjaxResult getProjectDetails(@PathVariable("projectId") Long projectId) {
        return success(antHospitalProjectService.selectProjectDetail(projectId));
    }

    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getProjectModify(@RequestParam Long projectId) {
        return success(antHospitalProjectService.selectProjectModify(projectId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:project:edit')")
    @Log(title = "项目信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/modify/{projectId}")
    public AjaxResult editModify(@PathVariable("projectId") Long projectId) {
        int isModify = 1;
        return toAjax(antHospitalProjectService.updateProjectModify(projectId, isModify));
    }
}
